var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgArr: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    var bgc = wx.getStorageSync('color')
    var types = options.types
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    that.setData({
      bgc: bgc
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },
  input: function(e) {
    console.log(e)
    var that = this
    that.setData({
      kewords: e.detail.value
    })
  },
  subClick() {

    var that = this
    if (that.data.kewords == "") {
      wx.showToast({
        title: '不能为空，请填写症状关键字',
        icon: 'none'
      })
    } else {
      var kewords = JSON.stringify(that.data.kewords)
      var imgArr = JSON.stringify(that.data.imgArr)
      wx.navigateTo({
        url: '/hyb_yl/userLife/pages/doctor/doctor?kewords=' + kewords + '&imgArr=' + imgArr,
      })
    }
  },
  //删除图片
  delImg: function(e) {
    var that = this
    console.log(e)
    var index = e.currentTarget.dataset.index
    var imgArr = that.data.imgArr
    imgArr.splice(index, 1)
    that.setData({
      imgArr: imgArr
    })
  },
  //添加图片
  addImg: function() {
    var that = this
    wx.chooseImage({
      count: 9,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths
        var imgArr = that.data.imgArr
        if (imgArr.length >= 9) {

        } else {
          imgArr = imgArr.concat(tempFilePaths)
          if (imgArr.length >= 9) {
            imgArr.length = 9
          }
        }
        that.setData({
          imgArr: imgArr
        })
      }
    })
  },

})